<%@page import="org.madmac.setor.SetorDao"%>
<%@page import="org.madmac.setor.Setor"%>
<%@page import="java.util.List"%>
<%@page import="java.util.List"%>
<%@page import="org.madmac.maquina.MaquinaDao"%>
<%@page import="org.madmac.maquina.Maquina"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
			pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- VERIFICA SE O USUÁRIO ESTÁ COM O COOKIE VÁLIDO, SENÃO O REDIRECIONA PARA A PÁGINA DE LOGIN -->
<%@ include file="/log/verify_login.jsp" %>
<!-- VERIFICA SE O USUÁRIO TEM PERMISSÃO DE ACESSAR A PÁGINA, SENÃO REDIRECIONA PARA A PÁGINA INICIAL -->
<%@include file="/log/sup_page.jsp" %>

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Editar Máquina</title>
      <link rel="icon" href="/madmac/favicon.ico" type="image/x-icon" />
      <link rel="shortcut icon" href="/madmac/favicon.ico" type="image/x-icon" />
      <link rel="stylesheet" href="/madmac/menu_madmac_files/cbcscbmenu_madmac.css" type="text/css" />
		<link rel="stylesheet" href="/madmac/estilos/madmac_tables.css" type="text/css" />
      <link rel="stylesheet" href="/madmac/estilos/madmac_inputs.css" type="text/css" />
		<link rel="stylesheet" href="/madmac/autocomplete/sugestoes.css" type="text/css" />
		<script type="text/javascript" src="/madmac/autocomplete/bibliotecaAjax.js" charset="UTF-8"></script>
      <script type="text/javascript" src="/madmac/autocomplete/sugestoes.js" charset="UTF-8"></script>
      <script type="text/javascript" src="/madmac/madmacproject.js" charset="UTF-8"></script>

      <script language="JavaScript" type="text/javascript">setNextField('sistema_op');
			setCurrentForm('atualizar_maquina');
			setNextPage('update_maquina.jsp');</script>

   </head>
   <body onload="document.getElementById('sistema_op').focus()">

      <div class="logotype"><img src="/madmac/madmac-logo-1.0.1.png" height="120%" alt="MAD MAC"></div>

      <div class="menu_principal">
			<%@ include file="/common_pages/menu.jsp" %>
      </div>

      <div class="search_mac">
			<%@include file="/common_pages/search_mac.jsp" %>
      </div>

      <div class="corpo">
			<p><br/></p>
				<%

				  int search_tombamento = Integer.parseInt(request.getParameter("tombamento"));
				  try {

					  Maquina edit_maquina = MaquinaDao.getInstance().findByTombamento(search_tombamento);
					  String caminho = MaquinaDao.getInstance().selectHostDetails(search_tombamento);
				%>
			<form action="/madmac/maquina/update_maquina.jsp" method="post" name="atualizar_maquina">
				<table width="50%" align="center" border="0" cellpadding="12" cellspacing="0" rules="all" class="main_table">
					<tr>
						<td width="5%"></td>
						<td class="meta_cell">Tombamento</td>
						<td class="data_cell">
							<input type="text" id="tomb_disable" name="tomb_disable" value="<%=edit_maquina.getTombamento()%>" maxlength="5"
									 class="input_fields" disabled="disable" /></td>
						<td></td>
					</tr>
					<tr>
						<td></td>
						<td class="meta_cell">Sistema Operacional</td>
						<td class="data_cell">
							<select name="sistema_op" class="select_fields" onfocus="nextfield='modelo'" id="sistema_op">
								<%
							 String[] so = new String[4];
							 so[0] = "Linux";
							 so[1] = "MacOS";
							 so[2] = "Dual Boot";
							 so[3] = "Windows";

							 for (int i = 0; i < so.length; i++) {

								 if (edit_maquina.getSistemaOp().equals(so[i])) {
								%>
								<option value="<%=so[i]%>" selected="selected"><%=so[i]%></option>
								<%
									} else {
								%>
								<option value="<%=so[i]%>"><%=so[i]%></option>
								<%
								 }
							 }
								%>
							</select>
						</td>
						<td></td>
					</tr>
					<tr>
						<td></td>
						<td class="meta_cell" valign="top">Modelo</td>
						<td class="data_cell">
							<textarea name="modelo" rows="8" cols="40" disabled="disabled"></textarea><br/>
							<input type="checkbox" name="alt_modelo" value="true"><span style="color:#782121;">Alterar Modelo.</span>
						</td>
						<td class="cmd_cell" valign="top">
							<a href="<%=caminho%>">
								<img src="/madmac/icons/pdf.png" border="0" title=" Download PDF - Detalhes da Máquina " alt="">
							</a>
						</td>
					</tr>
					<tr>
						<td></td>
						<td class="meta_cell">Setor</td>
						<td class="data_cell">
							<select name="setor" class="select_fields" onfocus="nextfield='pessoa'">
								<option value="">Selecione o Setor</option>
								<%
							 int count_setor = 0;
							 try {
								 List<Setor> lista_setor = SetorDao.getInstance().selectAll();

								 count_setor = lista_setor.size();
								 for (int i = 0; i < lista_setor.size(); i++) {

									 Setor setor = lista_setor.get(i);
									 int code_setor = setor.getCodeSetor();
									 String nome = setor.getNome();

									 if (edit_maquina.getCode_setor() == code_setor) {
								%>
								<option value="<%=code_setor%>" selected="selected"><%=nome%></option>
								<%
										} else {
								%>
								<option value="<%=code_setor%>"><%=nome%></option>
								<%
										}
									}
								} catch (Exception e) {

								%>
								<option value="">Erro ao listar . . .</option>
								<%		  }

								%>
								<option value=""></option>
								<option value="">Total de Setores: <%=count_setor%></option>
							</select></td>
						<td></td>
					</tr>
					<tr>
						<td></td>
						<td class="meta_cell">Responsável</td>
						<td class="data_cell">
							<input type="text" id="pessoa" name="pessoa" value="<%=edit_maquina.getResponsavel() %>"
							maxlength="100" class="input_fields_Cap" onkeyup="Sugestoes('pessoas');" /></td>
						<td class="cmd_cell">
                     <span id="aviso"><img src="/madmac/icons/clock.png" style="visibility: inherit" alt=""></span>
						</td>
					</tr>
				</table>
				<br/>
				<input type="hidden" name="tombamento" value="<%=search_tombamento%>">
				<table width="50%" align="center" border="1" cellpadding="15" cellspacing="0" rules="rows" class="main_table">
               <tr class="menu_sql">
                  <td></td>
                  <td align="center">
                     <input type="reset" value="Refazer" class="reset_button" />
                  </td>
                  <td align="center">
                     <input type="submit" value="Adicionar" class="bSubmit_maquina" />
                  </td>
                  <td></td>
               </tr>
            </table>
				<input type="hidden" name="id_maquina" value="<%=edit_maquina.getId_maquina()%>" />
			</form>
			<p><br/></p>
				<%

				} catch (Exception e) {

				%>
			<p><br/></p>
         <table width="45%" align="center" border="1" cellpadding="5" cellspacing="0" rules="rows" class="main_table">
				<tr class="alert_cell">
               <td align="center" width="15%"><img src="/madmac/icons/file_alert.png" align="middle" width="64px" alt=""></td>
					<td><%=e.getMessage() %></td></tr>
				<tr>
               <td class="data_cell" align="right" colspan="2">
                  <input type="button" value="Voltar" class="bBack" onclick="javascript:history.go(-1)">
               </td>
				</tr>
			</table>
			<%
			  }

			%>
			<p><br/></p>
      </div>
			<!-- DIV QUE MOSTRA AS PESSOAS CADASTRADAS A MEDIDA QUE FOR DIGITANDO -->
      <div id="divPopup" class="sugestoes">
         <table id="tabela" bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="0" class="semCor"></table>
      </div>
			
      <div class="footer_madmac">
			<%@include file="/common_pages/footer.jsp" %>
      </div>
   </body>
</html>